<!DOCTYPE html>
<html>
    <head>
        <title>构造函数 </title>
		<meta charset="utf-8" />
    </head>
    <body>

    </body>
    <script>
        /*电影名字 movieName 
        类型 type 
        评分 rate 
        播放时间 showTime["12:00","15:00"]
        */
       /*var movie1 = {
           movieName: "007",
           type: "动作",
           rate: "9.0",
           showTime: ["12:00","15:00","17:00"]
       }
       var movie2 = {
           movieName: "指环王",
           type: "动画",
           rate: "8.5",
           showTime: ["15:00","20:00","21:00"]
       }*/

       //为了将普通函数和生成对象的函数区分开，出现了构造函数的概念
       /*function creatMovie(movieName,type,rate,showTime){
           var movieObj = {};
           movieObj.movieName = movieName;
           movieObj.type = type;
           movieObj.rate = rate;
           movieObj.showTime = showTime;
           movieObj.getNextShowing = function(){
               var current = 11;
               for(var i = 0; i < movieObj.showTime.length; i++){
                   if(current < parseInt(movieObj.showTime[i])){
                       console.log("下一次的播放时间" + movie.showTime);
                   }
               }
           }
           return movieObj;
       }

       var movie1 = creatMovie("007", "动作", "9.0", ["12:00","15:00","17:00"]);
       var movie2 = creatMovie("指环王", "动画", "8.5", ["15:00","20:00","21:00"]);
       console.log(movie1);
       console.log(movie2);*/

       //构造函数
       /*构造函数命名，单词首字母均为大写*/
       function CreatMovie(movieName, type, rate, showTime){
           this.movieName = movieName;//前一个movieName是属性名，后一个movieName是传入参数  
           this.type = type;
           this.rate = rate;
           this.showTime = showTime;
           this.getNextShowing = function(){
               var current = 10;
               for(var i = 0; i < this.showTime.length; i++){
                   var timer = parseInt(this.showTime[i]);
                   if(current < timer){
                       console.log(this.movieName + "下一次的播放时间" + this.showTime);
                       break;
                   }
               }
           }
       }
       //对象实例化过程，需要使用关键字new
       var movie1 = new CreatMovie("007", "动作", "9.0", ["12:00","15:00","17:00"]);
       var movie2 = new CreatMovie("指环王", "动画", "8.5", ["15:00","20:00","21:00"]);
       console.log(movie1);
       movie1.getNextShowing();
       console.log(movie2);
    </script>
</html>